<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__tenant}">
      <div class="custom-header">
        <div class="left-box">
          <span>租户管理</span>
        </div>
        <div class="right-box">
          <div class="button-box" v-if="$hasPermission('sys:tenant:save')">
            <el-button size="small" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
            <el-button size="small" type="primary" icon="el-icon-arrow-down"></el-button>
          </div>
        </div>
      </div>
      <el-form class="table-form-wrap" size="small" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.tenantId" placeholder="租户ID" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.tenantName" placeholder="租户名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.linkman" placeholder="联系人" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('sys:tenant:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table :max-height="tabHeight" stripe :border="false" size="small" v-loading="dataListLoading" :data="dataList" @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;" @row-click="rowClick">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>
        <el-table-column prop="tenantId" label="租户ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="tenantName" label="租户名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="domain" label="域名地址" header-align="center" align="center"></el-table-column>
        <el-table-column prop="backgroundUrl" label="系统背景" header-align="center" align="center"></el-table-column>
        <el-table-column prop="linkman" label="联系人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="contactNumber" label="联系电话" header-align="center" align="center"></el-table-column>
        <el-table-column prop="address" label="联系地址" header-align="center" align="center"></el-table-column>
        <el-table-column prop="accountNumber" label="账号额度" header-align="center" align="center"></el-table-column>
        <el-table-column prop="expireTime" label="过期时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="datasourceId" label="数据源ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="licenseKey" label="授权码" header-align="center" align="center"></el-table-column>
        <el-table-column prop="creator" label="创建人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="deptId" label="创建部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updater" label="修改人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="修改时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="状态" header-align="center" align="center"></el-table-column>
        <el-table-column prop="isDeleted" label="是否已删除" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('sys:tenant:update')" type="text" size="small"
              @click.stop="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('sys:tenant:delete')" type="text" size="small"
              @click.stop="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './tenant-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/tenant/page',
        getDataListIsPage: true,
        deleteURL: '/sys/tenant',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        tenantId: '',
        tenantName: '',
        linkman: ''
      },
      tabHeight: '400'
    }
  },
  components: {
    AddOrUpdate
  },
  mounted () {
    this.$nextTick(() => {
      this.tabHeight = this.$getClientHeight() - 182 - 32 + 'px'
    })
  },
  methods: {
    rowClick (row, column, event) {
      this.addOrUpdateHandle(row.id)
    }
  }
}
</script>
